//
//  LadingRequireCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/6.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "LadingRequireCell.h"
#import "LJCustomTextView.h"

@interface LadingRequireCell ()<UITextViewDelegate>

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *serviceTitleLab;
@property (nonatomic, strong) UIView *serviceView;
@property (nonatomic, strong) UILabel *line1;
@property (nonatomic, strong) UILabel *prescriptionTitleLab;
@property (nonatomic, strong) UIView *prescriptionView;
@property (nonatomic, strong) UILabel *line2;
@property (nonatomic, strong) UITextField *shippingField;
@property (nonatomic, strong) UIButton *shippingBtn;
@property (nonatomic, strong) UILabel *line3;
@property (nonatomic, strong) UITextField *requireField;
@property (nonatomic, strong) UIButton *requireBtn;
@property (nonatomic, strong) UILabel *line4;
@property (nonatomic, strong) UITextField *styleField;
@property (nonatomic, strong) UIButton *styleBtn;
@property (nonatomic, strong) UILabel *lineStyle;
@property (nonatomic, strong) UITextField *weightField;
@property (nonatomic, strong) UILabel *line5;
@property (nonatomic, strong) UITextField *volumeField;
@property (nonatomic, strong) UILabel *line6;
@property (nonatomic, strong) UITextField *insuranceField;
@property (nonatomic, strong) UILabel *line7;
@property (nonatomic, strong) UILabel *fileTitleLab;
@property (nonatomic, strong) UILabel *fileCountLab;
@property (nonatomic, strong) LJCustomTextView *fileTextView;
@property (nonatomic, strong) UILabel *line8;
@property (nonatomic, strong) UILabel *remarkTitleLab;
@property (nonatomic, strong) UILabel *remarkCountLab;
@property (nonatomic, strong) LJCustomTextView *remarkTextView;
@property (nonatomic, strong) UIView *tipsView;

@end

@implementation LadingRequireCell

+ (instancetype)LadingRequireCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"LadingRequireCell";
    LadingRequireCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[LadingRequireCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.serviceTitleLab = [UILabel new];
        self.serviceTitleLab.textColor = HexColor(0x2B2C44);
        self.serviceTitleLab.font = [UIFont systemFontOfSize:14];
        self.serviceTitleLab.text = @"服务方式";
        [self.bgView addSubview:self.serviceTitleLab];
        
        self.serviceView = [UIView new];
        [self.bgView addSubview:self.serviceView];
        
        self.line1 = [UILabel new];
        self.line1.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line1];
        
        self.prescriptionTitleLab = [UILabel new];
        self.prescriptionTitleLab.textColor = HexColor(0x2B2C44);
        self.prescriptionTitleLab.font = [UIFont systemFontOfSize:14];
        self.prescriptionTitleLab.text = @"运输时效";
        [self.bgView addSubview:self.prescriptionTitleLab];
        
        self.prescriptionView = [UIView new];
        [self.bgView addSubview:self.prescriptionView];
        
        self.line2 = [UILabel new];
        self.line2.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line2];
        
        self.shippingField = [UITextField new];
        self.shippingField.textColor = HexColor(0x2B2C44);
        self.shippingField.font = [UIFont systemFontOfSize:14];
        self.shippingField.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.shippingField];
        
        self.shippingBtn = [UIButton new];
        [self.shippingBtn addTarget:self action:@selector(shippingClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.shippingBtn];
        
        self.line3 = [UILabel new];
        self.line3.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line3];
        
        self.requireField = [UITextField new];
        self.requireField.textColor = HexColor(0x2B2C44);
        self.requireField.font = [UIFont systemFontOfSize:14];
        self.requireField.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.requireField];
        
        self.requireBtn = [UIButton new];
        [self.requireBtn addTarget:self action:@selector(requireClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.requireBtn];
        
        self.line4 = [UILabel new];
        self.line4.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line4];
        
        self.styleField = [UITextField new];
        self.styleField.textColor = HexColor(0x2B2C44);
        self.styleField.font = [UIFont systemFontOfSize:14];
        self.styleField.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.styleField];
        
        self.styleBtn = [UIButton new];
        [self.styleBtn addTarget:self action:@selector(jieSuanClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.styleBtn];
        
        self.lineStyle = [UILabel new];
        self.lineStyle.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.lineStyle];
        
        self.weightField = [UITextField new];
        self.weightField.textColor = HexColor(0x2B2C44);
        self.weightField.font = [UIFont systemFontOfSize:14];
        self.weightField.placeholder = @"";
        self.weightField.textAlignment = NSTextAlignmentRight;
        self.weightField.keyboardType = UIKeyboardTypeDecimalPad;
        self.weightField.userInteractionEnabled = NO;
        [self.bgView addSubview:self.weightField];
        
        self.line5 = [UILabel new];
        self.line5.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line5];
        
        self.volumeField = [UITextField new];
        self.volumeField.textColor = HexColor(0x2B2C44);
        self.volumeField.font = [UIFont systemFontOfSize:14];
        self.volumeField.placeholder = @"";
        self.volumeField.textAlignment = NSTextAlignmentRight;
        self.volumeField.keyboardType = UIKeyboardTypeDecimalPad;
        self.volumeField.userInteractionEnabled = NO;
        [self.bgView addSubview:self.volumeField];
        
        self.line6 = [UILabel new];
        self.line6.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line6];
        
        self.insuranceField = [UITextField new];
        self.insuranceField.textColor = HexColor(0x2B2C44);
        self.insuranceField.font = [UIFont systemFontOfSize:14];
        self.insuranceField.placeholder = @"请输入";
        self.insuranceField.textAlignment = NSTextAlignmentRight;
        self.insuranceField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.insuranceField addTarget:self action:@selector(insuranceFieldChange:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.insuranceField];
        
        self.line7 = [UILabel new];
        self.line7.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line7];
        
        self.fileTitleLab = [UILabel new];
        self.fileTitleLab.textColor = HexColor(0x2B2C44);
        self.fileTitleLab.font = [UIFont systemFontOfSize:14];
        self.fileTitleLab.text = @"随附文件";
        [self.bgView addSubview:self.fileTitleLab];
        
        self.fileCountLab = [UILabel new];
        self.fileCountLab.textColor = HexColor(0xBDBED9);
        self.fileCountLab.font = [UIFont systemFontOfSize:12];
        self.fileCountLab.text = @"0/50";
        [self.bgView addSubview:self.fileCountLab];
        
        self.fileTextView = [LJCustomTextView new];
        self.fileTextView.placeholder = @"请输入";
        self.fileTextView.textColor = HexColor(0x2B2C44);
        self.fileTextView.font = [UIFont systemFontOfSize:14];
        self.fileTextView.textLength = 50;
        __weak_self;
        self.fileTextView.countBlock = ^(NSString * _Nonnull str) {
            weakself.fileCountLab.text = str;
            if (weakself.fileBlock) {
                weakself.fileBlock(weakself.fileTextView.text);
            }
        };
        [self.bgView addSubview:self.fileTextView];
        
        self.line8 = [UILabel new];
        self.line8.backgroundColor = HexColor(0xF2F2F5);
        [self.bgView addSubview:self.line8];
        
        self.remarkTitleLab = [UILabel new];
        self.remarkTitleLab.textColor = HexColor(0x2B2C44);
        self.remarkTitleLab.font = [UIFont systemFontOfSize:14];
        self.remarkTitleLab.text = @"备注";
        [self.bgView addSubview:self.remarkTitleLab];
        
        self.remarkCountLab = [UILabel new];
        self.remarkCountLab.textColor = HexColor(0xBDBED9);
        self.remarkCountLab.font = [UIFont systemFontOfSize:12];
        self.remarkCountLab.text = @"0/255";
        [self.bgView addSubview:self.remarkCountLab];
        
        self.remarkTextView = [LJCustomTextView new];
        self.remarkTextView.placeholder = @"请输入";
        self.remarkTextView.textColor = HexColor(0x2B2C44);
        self.remarkTextView.font = [UIFont systemFontOfSize:14];
        self.remarkTextView.textLength = 255;
        self.remarkTextView.countBlock = ^(NSString * _Nonnull str) {
            weakself.remarkCountLab.text = str;
            if (weakself.remarkBlock) {
                weakself.remarkBlock(weakself.remarkTextView.text);
            }
        };
        [self.bgView addSubview:self.remarkTextView];
        
        self.tipsView = [UIView new];
        [self.bgView addSubview:self.tipsView];
    }
    return self;
}

- (void)shippingClick {
    if (self.shippingBlock) {
        self.shippingBlock();
    }
}

- (void)requireClick {
    if (self.requireBlock) {
        self.requireBlock();
    }
}

- (void)jieSuanClick {
    if (self.jieSuanBlock) {
        self.jieSuanBlock();
    }
}

- (void)insuranceFieldChange:(UITextField *)field {
    if (self.insuranceBlock) {
        self.insuranceBlock(field.text);
    }
}

-(void)setModel:(LadingRequireMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.line1.frame = CGRectMake(10, 60, self.bgView.nim_width - 20, 1);
    
    self.serviceTitleLab.nim_left = self.line1.nim_left;
    [self.serviceTitleLab sizeToFit];
    self.serviceTitleLab.nim_top = (self.line1.nim_top - self.serviceTitleLab.nim_height) * 0.5;
    
    self.serviceView.nim_left = self.serviceTitleLab.nim_right + 10;
    self.serviceView.nim_centerY = self.serviceTitleLab.nim_centerY;
    self.serviceView.nim_height = 30;
    self.serviceView.nim_width = self.bgView.nim_width - self.serviceView.nim_left;
    
    if (self.model.delivery.count) {
        __block CGFloat btnLeft = self.serviceView.nim_width;
        [self.serviceView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self.model.delivery enumerateObjectsUsingBlock:^(LadingDeliveryModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIButton *btn = [UIButton new];
            btn.nim_width = [FactoryMethod sizeWithText:obj.name font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(0, 0)].width + 30;
            btn.nim_height = self.serviceView.nim_height;
            btn.nim_left = btnLeft - 15 - btn.nim_width;
            btn.nim_top = 0;
            [btn setTitle:obj.name forState:0];
            if (obj.isSelected) {
                btn.backgroundColor = Color_ThemeColor;
                [btn setTitleColor:HexColor(0xffffff) forState:0];
            }else {
                btn.backgroundColor = HexColor(0xF2F2F5);
                [btn setTitleColor:HexColor(0xBDBED9) forState:0];
            }
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 15;
            btn.tag = idx;
            [btn addTarget:self action:@selector(serviceClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.serviceView addSubview:btn];
            btnLeft = btn.nim_left;
        }];
    }
    
    self.line2.frame = CGRectMake(self.line1.nim_left, self.line1.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.prescriptionTitleLab.nim_left = self.line2.nim_left;
    [self.prescriptionTitleLab sizeToFit];
    self.prescriptionTitleLab.nim_top = self.line1.nim_bottom + (60 - self.prescriptionTitleLab.nim_height) * 0.5;
    
    self.prescriptionView.nim_left = self.prescriptionTitleLab.nim_right + 10;
    self.prescriptionView.nim_centerY = self.prescriptionTitleLab.nim_centerY;
    self.prescriptionView.nim_height = 30;
    self.prescriptionView.nim_width = self.bgView.nim_width - self.prescriptionView.nim_left;
    
    if (self.model.tranTime.count) {
        __block CGFloat btnLeft = self.prescriptionView.nim_width;
        [self.prescriptionView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self.model.tranTime enumerateObjectsUsingBlock:^(LadingTranTimeModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIButton *btn = [UIButton new];
            btn.nim_width = [FactoryMethod sizeWithText:obj.name font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(0, 0)].width + 30;
            btn.nim_height = self.prescriptionView.nim_height;
            btn.nim_left = btnLeft - 15 - btn.nim_width;
            btn.nim_top = 0;
            [btn setTitle:obj.name forState:0];
            if (obj.isSelected) {
                btn.backgroundColor = Color_ThemeColor;
                [btn setTitleColor:HexColor(0xffffff) forState:0];
            }else {
                btn.backgroundColor = HexColor(0xF2F2F5);
                [btn setTitleColor:HexColor(0xBDBED9) forState:0];
            }
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 15;
            btn.tag = idx;
            [btn addTarget:self action:@selector(tranTimeClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.prescriptionView addSubview:btn];
            btnLeft = btn.nim_left;
        }];
    }
    
    self.line3.frame = CGRectMake(self.line1.nim_left, self.line2.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.shippingField.frame = CGRectMake(self.line1.nim_left, self.line2.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *shipTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.shippingField.nim_width * 0.5, self.shippingField.nim_height)];
    shipTitleLab.text = @"运输方式";
    shipTitleLab.textColor = HexColor(0x2B2C44);
    shipTitleLab.font = [UIFont systemFontOfSize:14];
    self.shippingField.leftView = shipTitleLab;
    self.shippingField.leftViewMode = UITextFieldViewModeAlways;
    
    self.shippingField.text = self.model.shippingMode.length?self.model.shippingMode:@"";
    
    UIImageView *shipImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    shipImgView.image = [UIImage imageNamed:@"icon_arrow_down"];
    self.shippingField.rightView = shipImgView;
    self.shippingField.rightViewMode = UITextFieldViewModeAlways;
    
    self.shippingBtn.frame = self.shippingField.frame;
    
    self.line4.frame = CGRectMake(self.line1.nim_left, self.line3.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.requireField.frame = CGRectMake(self.line1.nim_left, self.line3.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *requireTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.requireField.nim_width * 0.5, self.requireField.nim_height)];
    requireTitleLab.text = @"车辆要求";
    requireTitleLab.textColor = HexColor(0x2B2C44);
    requireTitleLab.font = [UIFont systemFontOfSize:14];
    self.requireField.leftView = requireTitleLab;
    self.requireField.leftViewMode = UITextFieldViewModeAlways;
    
    self.requireField.text = self.model.carRequireMode.length?self.model.carRequireMode:@"";
    
    UIImageView *requireImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    requireImgView.image = [UIImage imageNamed:@"icon_arrow_down"];
    self.requireField.rightView = requireImgView;
    self.requireField.rightViewMode = UITextFieldViewModeAlways;
    
    self.requireBtn.frame = self.requireField.frame;
    
    self.lineStyle.frame = CGRectMake(self.line1.nim_left, self.line4.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.styleField.frame = CGRectMake(self.line1.nim_left, self.line4.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *styleTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.styleField.nim_width * 0.5, self.styleField.nim_height)];
    styleTitleLab.text = @"结算方式";
    styleTitleLab.textColor = HexColor(0x2B2C44);
    styleTitleLab.font = [UIFont systemFontOfSize:14];
    self.styleField.leftView = styleTitleLab;
    self.styleField.leftViewMode = UITextFieldViewModeAlways;
    
    self.styleField.text = self.model.jieSuanType.length?self.model.jieSuanType:@"";
    
    UIImageView *styleImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    styleImgView.image = [UIImage imageNamed:@"icon_arrow_down"];
    self.styleField.rightView = styleImgView;
    self.styleField.rightViewMode = UITextFieldViewModeAlways;
    
    self.styleBtn.frame = self.styleField.frame;
    
    self.line5.frame = CGRectMake(self.line1.nim_left, self.lineStyle.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.weightField.frame = CGRectMake(self.line1.nim_left, self.lineStyle.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *weightTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.weightField.nim_width * 0.5, self.weightField.nim_height)];
    weightTitleLab.text = @"总重量（kg）";
    weightTitleLab.textColor = HexColor(0x2B2C44);
    weightTitleLab.font = [UIFont systemFontOfSize:14];
    self.weightField.leftView = weightTitleLab;
    self.weightField.leftViewMode = UITextFieldViewModeAlways;
    
    self.weightField.text = self.model.allWeight.length?self.model.allWeight:@"";
    
    self.line6.frame = CGRectMake(self.line1.nim_left, self.line5.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.volumeField.frame = CGRectMake(self.line1.nim_left, self.line5.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *volumeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.volumeField.nim_width * 0.5, self.volumeField.nim_height)];
    volumeTitleLab.text = @"总体积（m³）";
    volumeTitleLab.textColor = HexColor(0x2B2C44);
    volumeTitleLab.font = [UIFont systemFontOfSize:14];
    self.volumeField.leftView = volumeTitleLab;
    self.volumeField.leftViewMode = UITextFieldViewModeAlways;
    
    self.volumeField.text = self.model.allVolume.length?self.model.allVolume:@"";
    
    self.line7.frame = CGRectMake(self.line1.nim_left, self.line6.nim_bottom + 60, self.line1.nim_width, self.line1.nim_height);
    
    self.insuranceField.frame = CGRectMake(self.line1.nim_left, self.line6.nim_bottom + 10, self.bgView.nim_width - 2 * self.line1.nim_left, 40);
    UILabel *insuranceTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.insuranceField.nim_width * 0.5, self.insuranceField.nim_height)];
    insuranceTitleLab.text = @"保险声明价值（元）";
    insuranceTitleLab.textColor = HexColor(0x2B2C44);
    insuranceTitleLab.font = [UIFont systemFontOfSize:14];
    self.insuranceField.leftView = insuranceTitleLab;
    self.insuranceField.leftViewMode = UITextFieldViewModeAlways;
    
    self.insuranceField.text = self.model.insuranceValue.length?self.model.insuranceValue:@"";
    
    self.fileTitleLab.nim_left = self.line2.nim_left;
    [self.fileTitleLab sizeToFit];
    self.fileTitleLab.nim_top = self.line7.nim_bottom + (60 - self.fileTitleLab.nim_height) * 0.5;
    
    self.fileCountLab.nim_left = self.fileTitleLab.nim_right + 10;
    [self.fileCountLab sizeToFit];
    self.fileCountLab.nim_bottom = self.fileTitleLab.nim_bottom;
    self.fileCountLab.nim_width += 50;
    
    self.fileTextView.frame = CGRectMake(self.fileTitleLab.nim_left, self.fileTitleLab.nim_bottom + 10, self.bgView.nim_width - 2 * self.fileTitleLab.nim_left, 80);
    
    self.fileTextView.customText = self.model.files.length?self.model.files:@"";
    
    self.line8.frame = CGRectMake(self.fileTextView.nim_left, self.fileTextView.nim_bottom + 5, self.fileTextView.nim_width, 1);
    
    
    self.remarkTitleLab.nim_left = self.line2.nim_left;
    [self.remarkTitleLab sizeToFit];
    self.remarkTitleLab.nim_top = self.line8.nim_bottom + (60 - self.remarkTitleLab.nim_height) * 0.5;
    
    self.remarkCountLab.nim_left = self.remarkTitleLab.nim_right + 10;
    [self.remarkCountLab sizeToFit];
    self.remarkCountLab.nim_bottom = self.remarkTitleLab.nim_bottom;
    self.remarkCountLab.nim_width += 50;
    
    self.remarkTextView.frame = CGRectMake(self.remarkTitleLab.nim_left, self.remarkTitleLab.nim_bottom + 10, self.bgView.nim_width - 2 * self.remarkTitleLab.nim_left, 80);
    
    self.remarkTextView.customText = self.model.remark.length?self.model.remark:@"";
    
    if (self.model.tipRemarkArray.count) {
        self.tipsView.nim_left = self.remarkTextView.nim_left;
        self.tipsView.nim_top = self.remarkTextView.nim_bottom + 10;
        self.tipsView.nim_width = self.remarkTextView.nim_width;
        __block CGFloat btnLeft = 0;
        __block CGFloat btnTop = 0;
        CGFloat btnH = 30;
        __block CGFloat tipH = 0;
        [self.tipsView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        __weak_self;
        [self.model.tipRemarkArray enumerateObjectsUsingBlock:^(LadingRemarkModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CGFloat textW = [FactoryMethod sizeWithText:obj.name font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(0, 0)].width;
            CGFloat btnW = textW + 36 > weakself.tipsView.nim_width ? weakself.tipsView.nim_width : textW + 36;
            UIButton *btn = [UIButton new];
            btn.nim_left = btnLeft;
            btn.nim_top = btnTop;
            btn.nim_width = btnW;
            btn.nim_height = btnH;
            if (btnLeft + btn.nim_width > weakself.tipsView.nim_width) {
                btn.nim_left = 0;
                btn.nim_top += btnH + 5;
            }
            [btn setTitle:obj.name forState:0];
            [btn setTitleColor:Color_ThemeColor forState:0];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 4;
            btn.layer.borderColor = Color_ThemeColor.CGColor;
            btn.layer.borderWidth = 1;
            btn.tag = idx;
            [btn addTarget:self action:@selector(tipBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [weakself.tipsView addSubview:btn];
            btnLeft = btn.nim_right + 5;
            tipH = btn.nim_bottom;
        }];
        self.tipsView.nim_height = tipH;
        self.bgView.nim_height = self.tipsView.nim_bottom + 10;
    }else {
        self.tipsView.frame = CGRectZero;
        self.bgView.nim_height = self.remarkTextView.nim_bottom + 10;
    }
    
    self.height = self.bgView.nim_bottom + 10;
}

- (void)tranTimeClick:(UIButton *)sender {
    LadingTranTimeModel *model = self.model.tranTime[sender.tag];
    if (self.tranTimeBlock) {
        self.tranTimeBlock(model.Id);
    }
}

- (void)serviceClick:(UIButton *)sender {
    LadingDeliveryModel *model = self.model.delivery[sender.tag];
    if (self.serviceBlock) {
        self.serviceBlock(model.Id);
    }
}

- (void)tipBtnClick:(UIButton *)sender {
    LadingRemarkModel *model = self.model.tipRemarkArray[sender.tag];
    NSString *orText = self.remarkTextView.text;
    if (orText.length) {
        self.remarkTextView.customText = [NSString stringWithFormat:@"%@、%@",orText,model.name];
    }else {
        self.remarkTextView.customText = model.name;
    }
    if (self.remarkChooseBlock) {
        self.remarkChooseBlock(self.remarkTextView.text);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
